@model IndexReviewViewModel

@{
	ViewBag.Title = Resources.Shared.AppName + " - " + string.Format(Resources.Shared.IndexViewTitle, "Review");
}

<div class="view-container">
  <div class="view-header-container">
    <h2 class="view-header">@string.Format(Resources.Shared.IndexViewTitle, "Review")</h2>
  </div>
  <!-- Grid begin -->
  <div class="grid-view-container">
  	<div class="grid-top-buttons">
	  <input type="button" class="button create-button" title="@(Resources.Shared.Create)" onclick="document.location = '@Url.Action("Create", "Review")';" />	      
	  <input type="button" class="button report-button" title="@(Resources.Shared.Report)" onclick="document.location = '@Url.Action("Report", "Review")';" />	      
	</div>
    <div class="grid-view-search">
      <form id="ReviewGrid-form" action="">
	    <div class="grid-view-search-label-container">
          @Html.Label(Resources.Shared.Search)
        </div>
	    <div class="grid-view-search-input-container">
	      <input type="text" name="search" class="t-button" value="@ViewBag.SearchValue" />
	    </div>
	    <div class="grid-view-search-button-container">
	      <input type="button" name="search" class="button search-button" title="@(Resources.Shared.DoSearch)" onclick="Search('ReviewGrid-form', 'ReviewGrid','@Url.Action("Load", "Review")', CreateReviewRowData);" />
	      <input type="button" name="clean" class="button clean-button" title="@(Resources.Shared.Clean)" onclick="ClearAndSearch('ReviewGrid-form', 'ReviewGrid','@Url.Action("Load", "Review")', CreateReviewRowData);" />
	    </div>
	  </form>
    </div>
	<div class="grid-separator">
	</div>
    <div class="grid-view-panel"> 
	  <table id="ReviewGrid"></table>      
    </div>
	<div class="grid-separator">
	</div>
    <div class="grid-view-view-more">
      <input id="ReviewGrid-view-more-button" type="button" class="button view-more-button" value="@(Resources.Shared.ViewMore)" onclick="ViewMoreResults('ReviewGrid', '@Url.Action("Load", "Review")', CreateReviewRowData, @ViewBag.PageIndex, @ViewBag.PageSize)" />
	  <div class="grid-view-count">
		<span>@(Resources.Shared.GridTotal)<span id="ReviewGrid-total-count" class="count-number"></span></span>    
	  </div>
    </div>
	<div class="grid-bottom-buttons">
	  <input type="button" class="button create-button" title="@(Resources.Shared.Create)" onclick="document.location = '@Url.Action("Create", "Review")';" />	      
	  <input type="button" class="button report-button" title="@(Resources.Shared.Report)" onclick="document.location = '@Url.Action("Report", "Review")';" />      
	</div>
  </div>
  <!-- Grid end -->
</div> 
<!-- View container end -->

@section scripts{
<script type="text/javascript">

DefaultSearchEventTriggers("ReviewGrid-form");

$(document).ready(function () {
    $("#ReviewGrid").jqGrid({
        url: '@Url.Action("Load", "Review")',
        datatype: 'json',
        mtype: 'POST',
		autowidth: true,
		altRows: true,
		altclass: 'grid-alt-row',
		rowNum: @(ViewBag.PageSize * (ViewBag.PageIndex + 1)),
        colNames: ['Date', 'Rating', 'Comment', 'Customer', 'Product', '', '', ''],
		colModel: [
			{ index: 'Date', name: 'Date', sortable: true, resizable: false },
			{ index: 'Rating', name: 'Rating', sortable: true, resizable: false },
			{ index: 'Comment', name: 'Comment', sortable: true, resizable: false },
			{ index: 'Customer', name: 'Customer', sortable: false, resizable: false },
			{ index: 'Product', name: 'Product', sortable: false, resizable: false },
			{ name: 'edit', sortable: false, classes: 'grid-cell-edit', resizable: false },
			{ name: 'details', sortable: false, classes: 'grid-cell-details', resizable: false },
			{ name: 'delete', sortable: false, classes: 'grid-cell-delete', resizable: false },
		],
		gridComplete: 
            function(){ 
                var ids = jQuery("#ReviewGrid").jqGrid('getDataIDs'); 
                for(var i=0;i < ids.length;i++)
                { 
                    var rowId = ids[i]; 
                    var editHtml = '<a href="@Url.Action("Edit", "Review")/' + rowId + '" title="@Resources.Shared.Edit"><img src="@Url.Content("~/Content/Images/CRUD/edit.png")"/></a>';
					var detailsHtml = '<a href="@Url.Action("Details", "Review")/' + rowId + '" title="@Resources.Shared.Details"><img src="@Url.Content("~/Content/Images/CRUD/details.png")"/></a>';
					var deleteHtml = '<a href="#" onclick="return DeleteGridItem(\'ReviewGrid\', \'@Url.Action("Delete", "Review")\', \'' + rowId + '\')" title="@Resources.Shared.Delete"><img src="@Url.Content("~/Content/Images/CRUD/delete.png")"/></a>';
                    $("#ReviewGrid").jqGrid('setRowData', ids[i], { edit: editHtml, details: detailsHtml, 'delete': deleteHtml }); 
                }
				
				$("#ReviewGrid").jqGrid('setLabel', 'Date', '@Resources.ReviewResources.Date', 'grid-header-data', '');
				$("#ReviewGrid").jqGrid('setLabel', 'Rating', '@Resources.ReviewResources.Rating', 'grid-header-data', '');
				$("#ReviewGrid").jqGrid('setLabel', 'Comment', '@Resources.ReviewResources.Comment', 'grid-header-data', '');
				$("#ReviewGrid").jqGrid('setLabel', 'Customer', '@Resources.ReviewResources.Customer', 'grid-header-data', '');
				$("#ReviewGrid").jqGrid('setLabel', 'Product', '@Resources.ReviewResources.Product', 'grid-header-data', '');
				$("#ReviewGrid").jqGrid('setLabel', 'edit', '', 'grid-header-edit', '');
                $("#ReviewGrid").jqGrid('setLabel', 'details', '', 'grid-header-details', '');
                $("#ReviewGrid").jqGrid('setLabel', 'delete', '', 'grid-header-delete', '');		
				
				// Fix: jqgrid first row causes problems with fixed cols
				FixGridColumnSize({ gridId: "ReviewGrid", hasEdit: true, hasDetails: true, hasDelete: true });
            },
		loadComplete:
            function(data){ 
                SetGridTotalCount("ReviewGrid", data.records);
                HideMoreResults("ReviewGrid", data.records);
            }
    });
}); 

function CreateReviewRowData(data)
{
    return { Date: data['cell'][0], Rating: data['cell'][1], Comment: data['cell'][2], Customer: data['cell'][3], Product: data['cell'][4] };
}
</script>
}
